package com.kfm.login.model;

import com.kfm.login.model.request.Phone;
import lombok.Data;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

// validation 使用：
// 1. 实体类的字段上添加注解 @NotNull 非空 @Size 最大最小长度  @Pattern("reg") 匹配正则
// 2. @RequestBody @Validated KfmUser user 将请求体的参数封装成实体类的过程中自动调用校验规则 出错会抛出异常
// 3. BindingResult result
// 4. 全局异常处理 form json --> MethodArgumentNotValidException
// 5. 分组  创建一个空接口 一个业务需要的字段上添加（groups=接口.class）
// 当validated(接口.class) 校验的就是当前组别的字段内容

@Data
public class KfmUser implements Serializable {
    private Integer id;

    @NotNull(message = "用户名是最重要的，你长点心", groups = {com.kfm.login.model.request.Email.class})
    @Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{2,9}$")
    private String username;

    private String password;

    @NotNull(message = "手机号不能为空", groups = {Phone.class})
    @Pattern(regexp = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$", message = "手机号要填写正确", groups = {Phone.class})
    private String phoneNumber;

    @NotNull(message = "邮箱不能为空", groups = {com.kfm.login.model.request.Email.class})
    @Email(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", groups = {com.kfm.login.model.request.Email.class})
    private String email;

    private String nickname;

    private Date createTime;

    private Date loginTime;

    private Integer role;

    private Integer status;

    private List<Menu> menus;

    private static final long serialVersionUID = 1L;
}